;; Copyright © 2017 Kei Kebreau <kkebreau@posteo.net>

;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program.  If not, see <http://www.gnu.org/licenses/>.

(define-module (tetronimo)
  #:use-module (guix packages)
  #:use-module (guix download)
  #:use-module (guix build-system gnu)
  #:use-module ((guix licenses) #:prefix license:)
  #:use-module (gnu packages ncurses))

(define-public vitetris
  (package
   (name "vitetris")
   (version "0.57")
   (source
    (origin
     (method url-fetch)
     (uri (string-append "http://www.victornils.net/tetris/"
                         name "-" version ".tar.gz"))
     (sha256
      (base32
       "1hndj6mh010zfyqfzihhslkvhffd3dzsh5jyyrl8jbvfn74ad7qc"))))
   (build-system gnu-build-system)
   (arguments
    '(#:configure-flags '("CC=gcc")
      ;; The default $INSTALL variable tries to impose root user permissions
      ;; on its files and folders, but the root user is not present in the
      ;; build environment.
      #:make-flags '("INSTALL=install")
      #:tests? #f ; no check target
      #:phases
      (modify-phases %standard-phases
        (replace 'configure
          (lambda* (#:key outputs configure-flags #:allow-other-keys)
            (zero? (apply system* "./configure"
                          (string-append "--prefix="
                                         (assoc-ref outputs "out"))
                          configure-flags))))
        (add-after 'install 'rename-binary
          (lambda* (#:key outputs #:allow-other-keys)
            (let ((bin (string-append (assoc-ref outputs "out") "/bin")))
              (rename-file (string-append bin "/tetris")
                           (string-append bin "/vitetris")))
            #t)))))
   (home-page "http://www.victornils.net/tetris/")
   (synopsis "Terminal-based tetromino game")
   (description
    "vitetris is a terminal-based tetromino game with gameplay much like the
early Tetris games by Nintendo.")
   (license license:bsd-2)))

(define-public yetris
  (package
    (name "yetris")
    (version "2.3.0")
    (source
     (origin
       (method url-fetch)
       (uri (string-append "https://github.com/alexdantas/"
                           name "/archive/v" version ".tar.gz"))
       (file-name (string-append name "-" version ".tar.gz"))
       (sha256
        (base32
         "06dr4gbmk6iwy1x7za37i10xsqdfy3w39v6g5mg8a7in4lij433j"))))
    (build-system gnu-build-system)
    (arguments
     '(#:tests? #f ; no test target
       ;; Set DESTDIR to the appropriate folder, remove the "/usr" prefix from
       ;; the installation's base directory, and set gcc as the C compiler.
       #:make-flags (list (string-append "DESTDIR=" (assoc-ref %outputs "out"))
                          "PREFIX=" "CC=gcc")
       #:phases
       (modify-phases %standard-phases
         (delete 'configure)))) ; no configure script
    (inputs `(("ncurses" ,ncurses)))
    (home-page "https://github.com/alexdantas/yetris")
    (synopsis "Customizable tetromino game with a textual interface")
    (description "yetris is a customizable tetromino game for the terminal.
Features include:
@enumerate
@item Colors and animated interface
@item Customizable gameplay, with several game mode possibilities: ghost piece,
hold piece, slide left/right, invisible and custom initial level and noise
(like the old B-mode)
@item Customizable interface: up to 7 next pieces, toggle game borders, center
screen, modify game random algorithm
@item Settings available on in-game menus and options
@item Game profiles: settings are automatically saved and restored at startup.
Multple profiles supported.
@item Game statistics: cleared lines, individual and total pieces
@end enumerate")
    (license license:gpl3+)))
